package com.irate.provider;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SessionLogin {

	private SharedPreferences pref;
	private Editor editor;
	private int PRIVATE_MODE = 0;
	public static final String KEY_NAME = "name";
	public static final String KEY_PASS = "pass";
	public static final String KEY_IS_LOGIN = "isLogin";
	private static final String PREF_NAME = "irate";

	public SessionLogin(Context context) {
		pref = context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
	}

	public void createLoginSession(String name, String pass) {
		editor = pref.edit();
		editor.putString(KEY_NAME, name);
		editor.putString(KEY_PASS, pass);
		editor.commit();
	}

	public void setLoginState(Boolean state) {
		editor = pref.edit();
		editor.putBoolean(KEY_IS_LOGIN, state);
		editor.commit();
	}

	public String[] getLoginSession() {

		String[] ldata = new String[2];

		ldata[0] = pref.getString(KEY_NAME, "");
		ldata[1] = pref.getString(KEY_PASS, "");

		return ldata;
	}

	public Boolean getLoginState() {
		return pref.getBoolean(KEY_IS_LOGIN, false);

	}

	public Editor getEditor() {
		return editor;
	}

	public void setEditor(Editor editor) {
		this.editor = editor;
	}
}
